<?php 
namespace app\admin\validate;
use app\admin\code\AdminCode;
use app\admin\code\AuthCode;
use app\admin\code\BaseCode;
use app\admin\model\AdminModel;
use app\admin\model\BaseModel;
use think\Session;
use think\Validate;

class AdminValidate extends BaseValidate
{
    protected $_rule = [
        'id'       =>  'require',
        'pass_word'     =>  'require|max:16|min:6|check_password',
    ];
    protected $_field = [
        'id'=>'管理员',
        'pass_word'=>'密码',
    ];
    protected $_message = [
        'id.require' => BaseCode::PARAM_CANT_EMPTY,
        'pass_word.require' => BaseCode::PARAM_CANT_EMPTY,
        'pass_word.min' => BaseCode::PARAM_MIN,
        'pass_word.max' => BaseCode::PARAM_MAX,
        'pass_word.check_password' => BaseCode::PARAM_WRONG
    ];
    protected $_scene = [
        'edit_pass_word' => ['id','pass_word'],
    ];
    protected $_extend_rule = ['check_password'];
    public function check_password(AdminValidate $obj,$data){
        $this->_db_data = $obj->_model->findData(['id'=>Session::get('admin.id')]);
        $data = md5($data.$this->_db_data['salt']);
        if($this->_db_data['pass_word'] != $data){
            return false;
        }else{
            return true;
        }
    }
}


